﻿using Microsoft.Office.Interop.Excel;
using PanhuaWin.系统管理;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DataTable = System.Data.DataTable;

namespace PanhuaWin.通用
{
    public partial class Form已发未完工卷 : UIForm
    {
        public string 工厂编号;
        public Bus_Plan 卷信息 = new Bus_Plan();
        public string FormWorkType="酸洗";
        public Form已发未完工卷()
        {
            InitializeComponent();
        }

        private void uiButton查询_Click(object sender, EventArgs e)
        {
            ListData();
        }

        private void ListData()
        {
            string sql;
            sql = @"SELECT row_number() over(order by  计划日期,卷号 ) 序号,   工厂编号, 仓库编号, 库位编号, 存货编号, 卷号, 轧制规格, 成品规格, 去向, 材质,产地, 计划日期, 产线编号, 产线名称, 规格型号, 
                重量, 备注,客户 FROM      View_已发未完工卷 where 1=1 ";
            sql += " and 工厂编号='" + pub.全局工厂编号 + "' and 计划日期>='" + this.uiDatePicker开始日期.Value.ToString("yyyy-MM-dd") + "' ";
            sql += " and 计划日期<'" + this.uiDatePicker结束日期.Value.AddDays(1).ToString("yyyy-MM-dd") + "'";
            if (this.uiComboBox材质.SelectedText != "全部")
            {
                sql += " and 材质 ='" + this.uiComboBox材质.SelectedText + "'";
            }
            if (this.uiTextBox规格型号.Text.Trim() != "")
            {
                sql += " and 规格型号 ='" + this.uiTextBox规格型号.Text.Trim().Replace("--", "") + "'";
            }
            if (this.uiTextBox产地.Text.Trim() != "")
            {
                sql += " and 产地 ='" + this.uiTextBox产地.Text.Trim().Replace("--", "") + "'";
            }
            if (this.uiTextBox卷号.Text.Trim() != "")
            {
                sql += " and 卷号 like '%" + this.uiTextBox卷号.Text.Trim().Replace("--", "") + "%'";
            }
            if (this.uiComboBox去向.SelectedText.Trim() != "全部"&& this.uiComboBox去向.SelectedText.Trim() != "")
            {
                sql += " and 去向 ='" + this.uiComboBox去向.SelectedText.Trim().Replace("--", "") + "'";
            }
            if (this.uiTextBox轧制规格.Text.Trim() != "")
            {
                sql += " and 轧制规格 ='" + this.uiTextBox轧制规格.Text.Trim().Replace("--", "") + "'";
            }
            if (this.uiTextBox成品规格.Text.Trim() != "")
            {
                sql += " and 成品规格 ='" + this.uiTextBox成品规格.Text.Trim().Replace("--", "") + "'";
            }
           // sql += " and 产线名称='"+ this.uiComboBox产线.SelectedText +"'";


            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {

                this.uiDataGridView已发未结束.AutoGenerateColumns = false;
                this.uiDataGridView已发未结束.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.uiDataGridView已发未结束.DataSource = tb;
                this.uiDataGridView已发未结束.Refresh();
            }
            else
            {
                //this.uiDataGridView已发未结束.AutoGenerateColumns = false;
                //this.uiDataGridView已发未结束.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.uiDataGridView已发未结束.DataSource = null;
                this.uiDataGridView已发未结束.Refresh();
                MessageBox.Show("没有已发料未结束的卷可以选择", "提示", MessageBoxButtons.OK);
                return;

            }


        }

        private void Form已发未完工卷_Load(object sender, EventArgs e)
        {
            this.uiDatePicker开始日期.Value = DateTime.Today.AddMonths(-1);
            this.uiDatePicker结束日期.Value = DateTime.Today;
            pub.ListSteelAll(this.uiComboBox材质);
            pub.ListWorkLine(pub.全局工厂编号, FormWorkType, this.uiComboBox产线);
            pub.ListNextWorkTypeBytWorkTypeAll(pub.全局工厂编号, FormWorkType, this.uiComboBox去向);
        }
        private void uiDataGridView已发未结束_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (this.uiDataGridView已发未结束.Columns[e.ColumnIndex].Name == "C选择")
                {
                    //出库卷信息.guid = Guid.Parse(this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["Cguid"].Value.ToString());
                    卷信息.VolumeCodeNew = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C卷号"].Value.ToString();
                    卷信息.OriginalSize = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C规格型号"].Value.ToString();
                    卷信息.Material = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C材质"].Value.ToString();
                    卷信息.Address = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C产地"].Value.ToString();
                    卷信息.OutputSize = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C轧制规格"].Value.ToString();
                    卷信息.ProductSize = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C成品规格"].Value.ToString();
                    卷信息.NextWorkType = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C去向"].Value.ToString();
                    卷信息.Remark = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C备注"].Value.ToString();
                    卷信息.Weight =  this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C重量"].Value.ToString( );
                    卷信息.Customer= this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C客户"].Value.ToString();
                    //出库卷信息.InventoryName = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C存货名称"].Value.ToString();
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
        }
    }
}
